package com.tancire.sources.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.sources.domain.SurResourceCategory;
import com.tancire.sources.service.ISurResourceCategoryService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 资源类型Controller
 *
 * @author chenchao
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/sources/surResourceCategory")
public class SurResourceCategoryController extends BaseController {
    @Resource
    private ISurResourceCategoryService surResourceCategoryService;

    /**
     * 查询资源类型列表
     */
    @PreAuthorize("@ss.hasPermi('sources:surResourceCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurResourceCategory surResourceCategory) {
        startPage();
        List<SurResourceCategory> list = surResourceCategoryService.selectSurResourceCategoryList(surResourceCategory);
        return getDataTable(list);
    }

    /**
     * 查询资源类型列表
     */
    @PreAuthorize("@ss.hasPermi('sources:surResourceCategory:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(SurResourceCategory surResourceCategory) {
        List<SurResourceCategory> list = surResourceCategoryService.selectSurResourceCategoryList(surResourceCategory);
        return AjaxResult.success("查询成功", list);
    }

    /**
     * 导出资源类型列表
     */
    @PreAuthorize("@ss.hasPermi('sources:surResourceCategory:export')")
    @Log(title = "资源类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurResourceCategory surResourceCategory) {
        List<SurResourceCategory> list = surResourceCategoryService.selectSurResourceCategoryList(surResourceCategory);
        ExcelUtil<SurResourceCategory> util = new ExcelUtil<SurResourceCategory>(SurResourceCategory.class);
        util.exportExcel(response, list, "资源类型数据");
    }

    /**
     * 获取资源类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('sources:surResourceCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(surResourceCategoryService.selectSurResourceCategoryById(id));
    }

    /**
     * 新增资源类型
     */
    @PreAuthorize("@ss.hasPermi('sources:surResourceCategory:add')")
    @Log(title = "资源类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurResourceCategory surResourceCategory) {
        return toAjax(surResourceCategoryService.insertSurResourceCategory(surResourceCategory));
    }

    /**
     * 修改资源类型
     */
    @PreAuthorize("@ss.hasPermi('sources:surResourceCategory:edit')")
    @Log(title = "资源类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurResourceCategory surResourceCategory) {
        return toAjax(surResourceCategoryService.updateSurResourceCategory(surResourceCategory));
    }

    /**
     * 删除资源类型
     */
    @PreAuthorize("@ss.hasPermi('sources:surResourceCategory:remove')")
    @Log(title = "资源类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(surResourceCategoryService.deleteSurResourceCategoryByIds(ids));
    }
}
